package com.foo.web.controller.wechat;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.foo.common.annotation.Log;
import com.foo.common.enums.BusinessType;
import com.foo.wechat.domain.WxUser;
import com.foo.wechat.service.IWxUserService;
import com.foo.common.core.controller.BaseController;
import com.foo.common.core.domain.AjaxResult;
import com.foo.common.utils.poi.ExcelUtil;
import com.foo.common.core.page.TableDataInfo;

/**
 * 用户关联Controller
 *
 * @author foo
 * @date 2025-11-10
 */
@Controller
@RequestMapping("/wechat/user")
public class WxUserController extends BaseController
{
    private String prefix = "wechat/user";

    @Autowired
    private IWxUserService wxUserService;

    @RequiresPermissions("wechat:user:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/user";
    }

    /**
     * 查询用户关联列表
     */
    @RequiresPermissions("wechat:user:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WxUser wxUser)
    {
        startPage();
        List<WxUser> list = wxUserService.selectWxUserList(wxUser);
        return getDataTable(list);
    }

    @GetMapping("/listAjax")
    @ResponseBody
    public AjaxResult listAjax(WxUser wxUser)
    {
        List<WxUser> list = wxUserService.selectWxUserList(wxUser);
        return AjaxResult.success (list);
    }


    /**
     * 修改用户关联
     */
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        WxUser wxUser = wxUserService.selectWxUserById(userId);
        mmap.put("wxUser", wxUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户关联
     */
    @RequiresPermissions("wechat:user:edit")
    @Log(title = "用户关联", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxUser wxUser)
    {
        return toAjax(wxUserService.updateWxUser(wxUser));
    }

    /**
     * 删除用户关联
     */
    @RequiresPermissions("wechat:user:remove")
    @Log(title = "用户关联", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wxUserService.deleteWxUserByIds(ids));
    }
}
